package com.example.haoqisystem.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class EmailConfig {


    @Value("smtp.qq.com")
    private String host;

    @Value("587")
    private int port;

    @Value("2157834851@qq.com")
    private String username;

    @Value("adxcauaqdpgmecjd")
    private String password;

    @Value("smtp")
    private String protocol;

    @Value("true")
    private boolean auth;

    @Value("true")
    private boolean starttlsEnable;

    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(host);
        mailSender.setPort(port);
        mailSender.setUsername(username);
        mailSender.setPassword(password);
        mailSender.setProtocol(protocol);

        java.util.Properties properties = mailSender.getJavaMailProperties();
        properties.put("mail.smtp.auth", String.valueOf(auth));
        properties.put("mail.smtp.starttls.enable", String.valueOf(starttlsEnable));

        return mailSender;
    }
}
